home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / DataElem.java < prev    next >
Text File  |  1998-10-21  |  5KB  |  150 lines

  1. package com.symantec.itools.swing;
  2.  
  3. import java.awt.Color;
  4. import java.util.*;
  5.  
  6. /**
  7.  * DataElem custom data type optionally used by the JChart component that allows you to
  8.  *   specify label and color information associated with each data point
  9.  * @author Michael Hopkins, Symantec
  10.  */
  11.  
  12. public class DataElem
  13. {
  14.    protected double          data;    // the value at the data point
  15.    protected String          label;   // the name of the data point
  16.    protected java.awt.Color  color;   // the color of the data point;
  17.  
  18.    /**
  19.     *  Default Constructor
  20.     *  If a color isn't specified, a color is assigned from the color utility vector
  21.     */
  22.    public DataElem()
  23.    {
  24.         setData( 0.0 );
  25.         setLabel( "" );
  26.         setColor( (java.awt.Color) graphColors.elementAt( seed % graphColors.size()) );
  27.    }
  28.  
  29.    public DataElem( double value )
  30.    {
  31.         setData( value );
  32.         setLabel( "" );
  33.         setColor( (java.awt.Color) graphColors.elementAt( seed % graphColors.size()) );
  34.    }
  35.  
  36.    public DataElem( double value, String s )
  37.    {
  38.         setData( value );
  39.         setLabel( s );
  40.         setColor( (java.awt.Color) graphColors.elementAt( seed % graphColors.size()) );
  41.    }
  42.  
  43.    public DataElem( double value, String s, java.awt.Color c )
  44.    {
  45.         setData( value );
  46.         setLabel( s );
  47.         setColor( c );
  48.    }
  49.  
  50.    /**
  51.      * sets the data of current data element
  52.      * @param value double to be used for the given data point
  53.      * @see #getData
  54.      */
  55.    public void setData( double value )
  56.    {
  57.         data = value;
  58.    }
  59.  
  60.    /**
  61.      * gets the data of the current data element
  62.      * @return data (double) associated with the element
  63.      * @see #setData
  64.      */
  65.    public double getData( )
  66.    {
  67.         return data;
  68.    }
  69.  
  70.    /**
  71.      * sets the label of current data element
  72.      * @param s String to be used for the given data point
  73.      * @see #getLabel
  74.      */
  75.    public void setLabel( String s )
  76.    {
  77.         label = s;
  78.    }
  79.  
  80.    /**
  81.      * gets the label of the current data element
  82.      * @return label associated with the element
  83.      * @see #setLabel
  84.      */
  85.    public String getLabel()
  86.    {
  87.         return label;
  88.    }
  89.  
  90.    /**
  91.      * sets the color of current data element
  92.      * @param c color to be used for the given data point
  93.      * @see #getColor
  94.      */
  95.    public void setColor( java.awt.Color c )
  96.    {
  97.         color = c;
  98.    }
  99.  
  100.     /**
  101.      * gets the color of the current data element
  102.      * @return color associated with the element
  103.      * @see #setColor
  104.      */
  105.    public java.awt.Color getColor()
  106.    {
  107.         return color;
  108.    }
  109.  
  110.     /* Color utility vector useful for assigning colors to charts */
  111.     static public Vector graphColors;
  112.     static protected int seed = 0;
  113.  
  114.     static {
  115.         graphColors = new Vector( 33 );
  116.         graphColors.addElement( new Color ( 255, 128, 128 ));   // grapefruit
  117.         graphColors.addElement( new Color ( 255, 255, 128 ));   // lemon
  118.         graphColors.addElement( new Color ( 248, 174, 22 ));    // orange
  119.         graphColors.addElement( new Color ( 128, 255, 128 ));   // kiwi
  120.         graphColors.addElement( new Color ( 128, 255, 255 ));   // baby blue
  121.         graphColors.addElement( new Color ( 193, 66, 75 ));     // brick red
  122.         graphColors.addElement( new Color ( 0, 128, 255 ));     // royal blue
  123.         graphColors.addElement( new Color ( 255, 200, 228 ));   // pink
  124.         graphColors.addElement( new Color ( 171, 105, 216 ));   // plum
  125.         graphColors.addElement( new Color ( 234, 231, 159 ));   // sand
  126.         graphColors.addElement( new Color ( 251, 201, 106 ));   // apricot
  127.         graphColors.addElement( new Color ( 234, 234, 0 ));     // bananna
  128.         graphColors.addElement( new Color ( 33, 133, 131 ));    // teal
  129.         graphColors.addElement( new Color ( 128, 0, 128 ));     // deep purple
  130.         graphColors.addElement( new Color ( 184, 3, 252 ));     // violet
  131.         graphColors.addElement( new Color ( 109, 147, 108 ));   // olive
  132.         graphColors.addElement( new Color ( 6, 200, 249 ));     // light blue
  133.         graphColors.addElement( new Color ( 254, 122, 227 ));   // hot pink
  134.         graphColors.addElement( new Color ( 69, 180, 200 ));    // aqua
  135.         graphColors.addElement( new Color ( 214, 216, 120 ));   // corn
  136.         graphColors.addElement( new Color ( 135, 158, 165 ));   // blue-gray
  137.         graphColors.addElement( new Color ( 177, 228, 204 ));   // mint
  138.         graphColors.addElement( new Color ( 209, 202, 197 ));   // smog
  139.         graphColors.addElement( new Color ( 55, 157, 57 ));     // pea
  140.         graphColors.addElement( new Color ( 70, 47, 166 ));     // navy
  141.         graphColors.addElement( new Color ( 197, 188, 33 ));    // mustard
  142.         graphColors.addElement( new Color ( 44, 29, 103 ));     // nightfall
  143.         graphColors.addElement( new Color ( 35, 100, 100 ));    // forrest green
  144.         graphColors.addElement( new Color ( 104, 90, 43 ));     // chocolate
  145.         graphColors.addElement( new Color ( 117, 146, 1 ));     // lilypad
  146.         graphColors.addElement( new Color ( 134, 104, 34 ));    // brown
  147.         graphColors.addElement( new Color ( 201, 183, 129 ));   // tan
  148.         graphColors.addElement( new Color ( 159, 167, 120 ));   // heather
  149.     }
  150. }